package com.r_z.mapper;

import com.r_z.entity.UserRole;
import com.r_z.entity.Users;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;


/**
 * @author 梁俊
 * @date 2023/5/29
 * &@version 1.0
 */
@Mapper
public interface UsersMapper {


    /**
     * 验证登录
     * @param users 用户对象
     * @return user对象
     */
    @Select("select * from users where userName=#{userName} and userPwd=#{userPwd}")
    public Users checkLogin(Users users);


    /**
     * 根据id查询
     * @param users
     * @return
     */
    @Select("SELECT userId,userName,userPwd,userPhone,u.userRoleId,userAddress,us.userRoleName FROM users u INNER JOIN userRole us ON u.`userRoleId`=us.`userRoleId` where userId=#{userId}")
    public Users selectIdUser(int  userId);

    /**
     * 模糊查询加分页
     * @param map 集合
     * @return 返回集合数据
     */
    @Select("SELECT userId,userName,userPwd,userPhone,u.userRoleId,userAddress,us.userRoleName FROM users u INNER JOIN userRole us ON u.`userRoleId`=us.`userRoleId` where userName LIKE #{userName} limit #{page},#{limit}")
    public List<Users> selectLikeUsers(Map map);


    /**
     * 姓名模糊查查页数
     * @param userName
     * @return
     */
    @Select("select count(*) from users where userName like #{userName}")
    int selectUserNameCount(String userName);


    /**
     * 根据删除id
     * @param userId id
     * @return 返回成功数据
     */
    @Delete("delete from users where userId=#{userId}")
    public int deleteUsers(int userId);

    /**
     * 多个删除
     * @param userId
     * @return
     */
    public int deleteDuoUsers(List userId);


    /**
     * 根据id修改
     * @param users 数据
     * @return 返回成功数据
     */
    @Update("UPDATE users SET userName=#{userName},userPwd=#{userPwd},userPhone=#{userPhone},userAddress=#{userAddress},userRoleId=#{userRoleId},Remark=#{Remark} WHERE userId=#{userId} ")
    public int updateUsers(Users users);


    /**
     * 添加
     * @param users 对象
     * @return 返回成功数据
     */
    @Insert("insert into users(userName,userPwd,userPhone,userAddress,userRoleId,Remark) values(#{userName},#{userPwd},#{userPhone},#{userAddress},#{userRoleId},#{Remark})")
    public int addUsers(Users users);


    /**
     * 根据id修改角色名称
     * @param userRole
     * @return
     */
    @Update("update userRole set userRoleName=#{userRoleName} where userRoleId=#{userRoleId}")
    public int updateUserRolew(int userRoleId,String userRoleName);

}
